package controller

import (
	"hft/Http/Models/request"
	services "hft/Http/Services"
	utils "hft/Http/Utils"
	"strconv"

	"github.com/gin-gonic/gin"
)

type ShopRoute struct{}

func (*ShopRoute) CreateShopRoute(c *gin.Context) {

	var data *request.ShopRouteRes

	c.ShouldBindJSON(&data)

	err := services.ShopRouteService.CreateShopRoute(data)

	if err != nil {
		utils.FailWithMessage(err.Error(), c)
		return
	}

	utils.Ok(c)

}

func (*ShopRoute) EditShopRoute(c *gin.Context) {

	var data *request.ShopRouteRes

	c.ShouldBindJSON(&data)

	err := services.ShopRouteService.EditShopRoute(data)

	if err != nil {
		utils.FailWithMessage(err.Error(), c)
		return
	}

	utils.Ok(c)
}

func (*ShopRoute) GetShopRouteList(c *gin.Context) {

	canJump, _ := strconv.Atoi(c.DefaultQuery("can_jump", "0"))

	data, err := services.ShopRouteService.GetShopRouteList(canJump)

	if err != nil {
		utils.FailWithMessage(err.Error(), c)
		return
	}

	utils.OkWithData(data, c)

}

func (*ShopRoute) Delete(c *gin.Context) {

	var ids request.IDS

	c.ShouldBindJSON(&ids)

	err := services.ShopRouteService.Delete(ids.IDS)

	if err != nil {
		utils.FailWithMessage(err.Error(), c)
		return
	}

	utils.Ok(c)

}

var ShopRouteController = new(ShopRoute)
